//****************************
//功能名称：Tab
//编写人  ：邬畏畏
//博客    :www.cnblogs.com/wsoft
//描述    :生成Tab控制所有功能
//****************************
var wwwTab = {
	version:"1.0",
	tabHeight:30,
	tabwidth:50,
	contentStyle:"",
	tabCount:2,
	tabCaptionAr:[],
	tabContentAr:[],
	parent:null
};

wwwTab.initTab = function(parent){  //parent是ID，string类型
	this.parent = document.getElementById(parent);
	var tabli = '<li id="Tab{id}" class="tabs">{caption}</li>';
	var tabContentli ='<li id="tabContent{id}">{caption}</li>';
	
	var divContent = '<div id="wwwTab" class="wwwTab">' + 
						'<ul id="Tabs">{nr1}' +
						'</ul>'+
						'<ul id="tabContent" class="tabContent" style="{style}">{nr2}'+
						'</ul>'+
					'</div>';
	/*   代码布局示例
	var divContent = '<div id="wwwTab" class="wwwTab">' + 
						'<ul id="Tabs">' +
							'<li id="Tab1" class="tabs">tab1</li>'+
							'<li id="Tab2" class="tabs">tab1</li>'+
						'</ul>'+
						'<ul id="tabContent" class="tabContent">'+
							'<li id="tabContent1">tab1content</li>'+
							'<li id="tabContent2">tab1content</li>'+
						'</ul>'+
					'</div>';
	*/
	var tmp = "",strA="",strB="";
	var i;
	for(i=0;i<this.tabCaptionAr.length;i++)
	{
		tmp = tabli.replace("{id}",i);
		tmp = tmp.replace("{caption}",this.tabCaptionAr[i]);
		strA = strA + tmp;

		tmp = tabContentli.replace("{id}",i);
		tmp = tmp.replace("{caption}",this.tabContentAr[i]);
		strB = strB + tmp;		
	}
	divContent = divContent.replace("{nr1}",strA);
	divContent = divContent.replace("{nr2}",strB);
	divContent = divContent.replace("{style}",this.contentStyle);
	this.parent.innerHTML=divContent;
	this.initEvent(parent);
	this.hideAllContent(parent,0);
}

wwwTab.initEvent = function(p){
	var t = document.getElementById(p);
	var child = t.children[0].children[0].children;
	var i;
	for(i=0;i<child.length;i++)
	{
		child[i].onclick = function(index){
			return function(){
				wwwTab.onclick(p,index);
			}
		}(i);
	}
}

wwwTab.onclick = function(p,e){
	var t = document.getElementById(p);
	var child = t.children[0].children[1].children;
	var i;
	var that;
	wwwTab.hideAllContent(p,e);
	for(i=0;i<child.length;i++)
	{
		that = child[i];
		if(child[i].id.substr(child[i].id.length-1)==e)
		{
			that.style.display="block";
		}
	}
}

wwwTab.hideAllContent = function(p,n){   //n=-1表示content全部隐藏，n=0,表示tabContent0显示
	var t = document.getElementById(p);
	var child = t.children[0].children[1].children;
	var i;
	var that;
	for(i=0;i<child.length;i++)
	{
		child[i].style.display="none";
	}
	child[n].style.display="block";
}


